/*
ID: guoxu1
PROG: concom
LANG: C++
*/
#include <fstream>
#include <string.h>
using namespace std;

ifstream fin( "concom.in" );
ofstream fout( "concom.out" );

#define cin fin
#define cout fout


const int MAX_COMPANIES_COUNT = 100;

class Array2
{
public:
  typedef int _TABLE[MAX_COMPANIES_COUNT][MAX_COMPANIES_COUNT];
  int (*pdata)[MAX_COMPANIES_COUNT];
  
  Array2()
  {
    pdata = new _TABLE;
    memset( pdata, 0, sizeof( _TABLE ) );
  } 
  
  ~Array2()
  {
    delete[] pdata;
  }
  
  int* operator[] (int i) const
  {
    return pdata[i];
  }
};

class Program
{
private:
  Array2 controls;
  Array2 owns;
  
  void check_prev( int a, int about )
  {
    for( int c = 0; c < MAX_COMPANIES_COUNT; c++ )
    {
      if( controls[c][a] != 1 ) continue;
      if( controls[c][about] == 1 ) continue;
      check_next(c, -1);
    }   
  }
  
  void check_next( int a, int about )
  {
    for( int c = 0; c < MAX_COMPANIES_COUNT; c++ )
    {
      if( controls[a][c] == 1 || a == c ) continue;
      if( about != -1 && (controls[about][c] != 1 || about == c) ) continue;
      
      int sum = owns[a][c];
      for( int k = 0; k < MAX_COMPANIES_COUNT; k++ )
      {
        if( controls[a][k] != 1 || a == k ) continue;
        sum += owns[k][c];
        if( sum >= 50 ) break;
      }
      
      if( sum >= 50 )
      {
        controls[a][c] = 1;
        check_prev(a, c);
      }
    }
  }
  
  void inc_own( int a, int b, int v )
  {
    if( v == 0 || a == b ) return;
    owns[a][b] = v;
    if( v >= 50 )
    {
      controls[a][b] = 1;
    }
    check_next(a, b);
    check_prev(a, b);
  }
  
public:
  int main()
  {
    int n = 0;
    cin >> n;
    for( int i = 0; i < n; i++ )
    {
      int i, j, p;
      cin >> i >> j >> p;
      
      inc_own( i-1, j-1, p );
    }
    
    for( int i = 0; i < MAX_COMPANIES_COUNT; i++ )
    for( int j = 0; j < MAX_COMPANIES_COUNT; j++ )
    {
      if( controls[i][j] == 1 )
      {
        cout << i + 1 << " " << j + 1 << endl;
      }
    }
    
    return 0;
  }
};


int main()
{
  return Program().main();
}
